<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <script type="text/javascript" src="./lib/angularJS/angular.min.js"></script>
    <title>活动列表</title>
    <style type="text/css">
    .pager{
      margin-top: 100px;
      display: inline-flex;
      justify-content: center;
    }
    .pager>nav{
      display: flex; align-items: center; padding: 3px;
	justify-content: center;
    }
    .pager>nav>button{
    	margin-left: 3px;
    }
    .pager>nav>ol[data-role="pageNumbers"]>li{
    	margin-left: 3px;
    	cursor: pointer;
    }
    .pager>nav>ol[data-role="pageNumbers"]{ display: flex; }
    .pager>nav>ol[data-role="pageNumbers"]>li.current{
		background-color: #5a98de;
		color: white;
    }
	</style>
</head>
<style type="text/css">
	.table-border{
		border-top: 1px solid #5a98de;
	}
	.table-bordered th, .table-bordered td{
		border-color: #5a98de;
	}
</style>
<body ng-app="myApp" ng-controller="myCtrl">
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 活动管理
        <span class="c-gray en">&gt;</span> 活动列表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
            title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <div class="page-container" style="text-align: center;">
        <div class="text-c">
            <button onclick="removeIframe()" class="btn btn-primary-outline radius">关闭选项卡</button>
            <span class="select-box inline btn-primary-outline radius">
                <select name="" class="select btn-primary-outline radius" id="select" ng-model='select' ng-change="selectval()" style="width: 100px;">
                	<option value="0">请选择分类</option>
                    <option value="{{class.id}}" ng-repeat="class in classall">{{class.type}}</option>
                </select>
            </span>
            <input class="btn btn-primary-outline radius" style="cursor:auto;" type="text" name="" ng-model="getsearch"  placeholder=" 活动名称" style="width:250px" class="input-text">
            <button class="btn btn-primary-outline radius" name="" id="" class="btn btn-success" type="submit" ng-click="search(getsearch)">
                <i class="Hui-iconfont">&#xe665;</i> 搜活动</button>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
                <thead>
                    <tr class="text-c">
                        <th width="80">ID</th>
                        <th >活动标题</th>
                        <th width="80">分类</th>
                        <th width="80">来源</th>
                        <th width="120">更新时间</th>
                        <th width="75">限制</th>
                        <th width="60">发布状态</th>
                        <th width="120">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="text-c" ng-repeat="active in activityall">
                        <td ng-cloak>{{active.id}}</td>
                        <td class="text-l" ng-cloak style="text-align: center !important;">
                            <u style="cursor:pointer" class="text-primary" 
                                title="查看" ng-cloak>{{active.activityName}}</u>
                        </td>
                        <td ng-cloak>{{active.type}}</td>
                        <td ng-cloak>{{active.username}}</td>
                        <td ng-cloak>{{active.activityDate}}</td>
                        <td ng-cloak>{{active.activityLimit}}</td>
                        <td class="td-status">
                            <span class="label label-success  radius" ng-class="{'label-danger':{{active.isdanger}},'label-warning':{{active.isdefault}}}" ng-cloak>{{active.release}}</span>
                        </td>
                        <td class="f-14 td-manage">
                        	<span style="text-decoration:none"  href="javascript:;" title="审核" ng-cloak>{{active.status}}</span>
                        </td>
                    </tr>
                   
                </tbody>
            </table>
            
            <!--<div class="pager" id="pager"></div>-->
        </div>
    </div>
    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->

    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
    
    <!--分页-->
    <script src="./lib/pagejs/dom/index.js"></script>
  	<script src="./lib/pagejs/bom/index.js"></script>
  	<script src="./lib/pagejs/pager/index.js"></script>
  	
    <script type="text/javascript">
    var pager;
    var classtype;
    var mt = document.querySelector('.mt-20');
	var information;
  	let app = angular.module('myApp', []);
		app.controller('myCtrl',['$scope', '$http',function ($scope, $http) {
		$scope.select = '0';
		$scope.currentPage = 0;
		$scope.getsearch = '';
		
			$scope.pagerFun = function(page,row){
				pager = document.createElement('div')
				pager.className = 'pager'
				mt.appendChild(pager)
			    new Pager({
			      element: pager,
			      currentPage: page,
			      totalPage: row,
			    })
			    let btn = document.querySelectorAll('.pager button')
			    btn.forEach(function(btn){
			    	btn.classList.add('btn','btn-primary-outline','radius')
			    })
			    let li = document.querySelectorAll('ol li')
			    li.forEach(function(li){
			    	li.classList.add('btn','btn-primary-outline','radius')
			    })
			    pager.addEventListener('pageChange', $scope.pageChange)
			}
			
			$scope.pageChange = function(e){
				$scope.currentPage = e.detail.page-1;
			    $scope.httpFun($scope.currentPage);
			}
			
			$scope.pagerSelect = function(page){
				if(information){
					$http({
						method: 'GET',
						url: '../Api/index.php?p=back&m=activity&a=getSearchPager',
//						headers : {'Content-Type':'application/x-www-form-urlencoded'},
						params: { 
						 	getsearch: information
						} 
					}).then(function successCallback(response) {
						let row = response.data;
						if($scope.currentPage == row){
							page = row
						}
						pager.removeEventListener('pageChange', $scope.pageChange)
		 				mt.removeChild(pager)
						$scope.pagerFun(page,parseInt(row));
					})
					return
				}
				if(classtype!='0' && classtype!=undefined){
					$http({
						method: 'GET',
						url: '../Api/index.php?p=back&m=activity&a=getClassPager',
//						headers : {'Content-Type':'application/x-www-form-urlencoded'},
						params: { 
						 	type: classtype
						} 
					}).then(function successCallback(response) {
						let row = response.data;
						if($scope.currentPage == row){
							page = row
						}
						pager.removeEventListener('pageChange', $scope.pageChange)
		 				mt.removeChild(pager)
						$scope.pagerFun(page,parseInt(row));
					})
					return
				}
				
				$http({
					method: 'GET',
					url: '../Api/index.php?p=back&m=activity&a=Pager',
//					headers : {'Content-Type':'application/x-www-form-urlencoded'},
				}).then(function successCallback(response) {
					if(pager){
						pager.removeEventListener('pageChange', $scope.pageChange)
						mt.removeChild(pager)
					}
					let row = response.data;
					if($scope.currentPage == row){
						page = row
					}
					$scope.pagerFun(page,parseInt(row));
				})
			}
			
			
			$scope.httpFun = function(page){
				
				if(information){
						$http({
							method: 'GET',
							url: '../Api/index.php?p=back&m=activity&a=getSearch',
//							headers : {'Content-Type':'application/x-www-form-urlencoded'},
							params: { 
								getsearch:information,page
						} 
						}).then(function successCallback(response) {
							$scope.pagerSelect(page+1);
							
							$scope.activityall = response.data;
							
							var all = response.data
							for (var i=0;i<all.length;i++) {
								if(all[i]['status'] == 0){
									$scope.activityall[i]['status'] = "待审核";
									$scope.activityall[i]['release'] = "未发布";
									$scope.activityall[i]['isdanger'] = false;
									$scope.activityall[i]['isdefault'] = true;
								}else if(all[i]['status'] == 1){
									$scope.activityall[i]['status'] = "已审核";
									$scope.activityall[i]['release'] = "已发布";
									$scope.activityall[i]['isdanger'] = false;
									$scope.activityall[i]['isdefault'] = false;
								}else{
									$scope.activityall[i]['status'] = "已审核";
									$scope.activityall[i]['release'] = "未通过";
									$scope.activityall[i]['isdanger'] = true;
									$scope.activityall[i]['isdefault'] = false;
								}
								if(all[i]['activityLimit'] == 0){
									$scope.activityall[i]['activityLimit'] = "不限男女";
								}else if(all[i]['activityLimit'] == 1){
									$scope.activityall[i]['activityLimit'] = "只限男生";
								}else{
									$scope.activityall[i]['activityLimit'] = "只限女生";
								}
							}
						}, function errorCallback(response) {
							console.log(response)
						});
					return;
				}
				if(classtype!='0' && classtype!=undefined){
						$http({
							method: 'GET',
							url: '../Api/index.php?p=back&m=activity&a=getClass',
//							headers : {'Content-Type':'application/x-www-form-urlencoded'},
							params: { 
								type:classtype,page
						} 
						}).then(function successCallback(response) {
							$scope.pagerSelect(page+1);
							
							$scope.activityall = response.data;
							
							var all = response.data
							for (var i=0;i<all.length;i++) {
								if(all[i]['status'] == 0){
									$scope.activityall[i]['status'] = "待审核";
									$scope.activityall[i]['release'] = "未发布";
									$scope.activityall[i]['isdanger'] = false;
									$scope.activityall[i]['isdefault'] = true;
								}else if(all[i]['status'] == 1){
									$scope.activityall[i]['status'] = "已审核";
									$scope.activityall[i]['release'] = "已发布";
									$scope.activityall[i]['isdanger'] = false;
									$scope.activityall[i]['isdefault'] = false;
								}else{
									$scope.activityall[i]['status'] = "已审核";
									$scope.activityall[i]['release'] = "未通过";
									$scope.activityall[i]['isdanger'] = true;
									$scope.activityall[i]['isdefault'] = false;
								}
								if(all[i]['activityLimit'] == 0){
									$scope.activityall[i]['activityLimit'] = "不限男女";
								}else if(all[i]['activityLimit'] == 1){
									$scope.activityall[i]['activityLimit'] = "只限男生";
								}else{
									$scope.activityall[i]['activityLimit'] = "只限女生";
								}
							}
						}, function errorCallback(response) {
							console.log(response)
						});
					return;
				}
				
				
				
				
					$http({
					method: 'GET',
					url: '../Api/index.php?p=back&m=activity&a=getAll',
//					headers : {'Content-Type':'application/x-www-form-urlencoded'},
					params: { 
					 	page
					} 
					}).then(function successCallback(response) {
						$scope.pagerSelect(page+1);
						
						$scope.activityall = response.data;
						
						var all = response.data
						for (var i=0;i<all.length;i++) {
							if(all[i]['status'] == 0){
								$scope.activityall[i]['status'] = "待审核";
								$scope.activityall[i]['release'] = "未发布";
								$scope.activityall[i]['isdanger'] = false;
								$scope.activityall[i]['isdefault'] = true;
							}else if(all[i]['status'] == 1){
								$scope.activityall[i]['status'] = "已审核";
								$scope.activityall[i]['release'] = "已发布";
								$scope.activityall[i]['isdanger'] = false;
								$scope.activityall[i]['isdefault'] = false;
							}else{
								$scope.activityall[i]['status'] = "已审核";
								$scope.activityall[i]['release'] = "未通过";
								$scope.activityall[i]['isdanger'] = true;
								$scope.activityall[i]['isdefault'] = false;
							}
							if(all[i]['activityLimit'] == 0){
								$scope.activityall[i]['activityLimit'] = "不限男女";
							}else if(all[i]['activityLimit'] == 1){
								$scope.activityall[i]['activityLimit'] = "只限男生";
							}else{
								$scope.activityall[i]['activityLimit'] = "只限女生";
							}
						}
					}, function errorCallback(response) {
						console.log(response)
					});
			}
			$scope.httpFun($scope.currentPage);
			
			
			
			
			//分类
			$scope.calssSelect = function(){
				$http({
					method: 'GET',
					url: '../Api/index.php?p=back&m=activity&a=class',
//					headers : {'Content-Type':'application/x-www-form-urlencoded'},
				}).then(function successCallback(response) {
					$scope.classall = response.data;
				})
			}
			$scope.calssSelect();
			
			
			
			
			//分类显示
	    	$scope.selectval=function(){
	    		classtype = $scope.select;
		   		$scope.httpFun(0)
		   } 
			
			
			
			
			//搜索
			$scope.search = function(){
				$scope.select = '0';
				classtype = $scope.select;
				information = $scope.getsearch;
				$scope.httpFun(0)
			}
			
			
		}]);
    </script>
</body>

</html>